package com.hmall.api.fallback;

import com.hmall.api.client.ItemClient;
import com.hmall.api.domain.dto.ItemDTO;
import com.hmall.api.domain.dto.OrderDetailDTO;
import com.hmall.api.domain.dto.PageInfo;
import com.hmall.api.domain.dto.PageQueryDTO;
import com.hmall.common.domain.PageDTO;
import com.hmall.common.domain.PageQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.Collection;
import java.util.List;
@Slf4j
public class ItemClientFactory implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.info("执行了fallback降级处理,{}",ids);
                return null;
            }

            @Override
            public ItemDTO queryItemById(Long id) {
                log.info("调用商品服务失败，返回null");
                return null;
            }

            @Override
            public void deductStock(List<OrderDetailDTO> items) {
                log.info("执行了fallback降级处理,{}",items);

            }

            @Override
            public void restoreStock(List<OrderDetailDTO> items) {
                log.error("调用item-service服务失败，降级处理",cause);

            }

            @Override
            public PageInfo<ItemDTO> queryItemByPage(PageQueryDTO query) {
                return null;
            }

        };
    }
}
